	
package com.piripo.xml;	
	
	
import com.piripo.entities.*;

import com.jrapid.controller.MarshallerBase;

import java.io.Writer;

public class DefaultMarshaller extends MarshallerBase {	

	public DefaultMarshaller(boolean full) {
		super(null, full, DefaultMarshaller.class);
	}
	
	public DefaultMarshaller() {
		super(null, false, DefaultMarshaller.class);
	}	
	
	public DefaultMarshaller(boolean full, String mapping) {
		super(mapping, full, DefaultMarshaller.class);
	}
	
		
	public void marshal(Writer writer, String nodeName, User obj, Boolean showSecondary) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<username>" + escape(obj.getUsername()) + "</username>");
		writer.write("<name>" + escape(obj.getName()) + "</name>");
		
		writer.write("</" + nodeName + ">");
	}
	
	public void marshalFull(Writer writer, String nodeName, User obj, Boolean foo) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<username>" + escape(obj.getUsername()) + "</username>");
		writer.write("<password>" + com.jrapid.util.Encrypter.hide(obj.getPassword()) + "</password>");
		
		for (Object o:obj.getPrivileges()) {
				
			writer.write("<privileges>" + escape(o) + "</privileges>");
					
		}
		for (Role o:obj.getRoles()) {
			marshal(writer, "roles", o, false);
		}
		writer.write("<name>" + escape(obj.getName()) + "</name>");
		writer.write("<accountType>" + escape(obj.getAccountType()) + "</accountType>");
		marshal(writer, "location", obj.getLocation(), false);
		for (Review o:obj.getReviews()) {
			marshal(writer, "reviews", o, false);
		}
		for (Experience o:obj.getExperience()) {
			marshal(writer, "experience", o, false);
		}
		writer.write("<photos>" + escape(obj.getPhotos()) + "</photos>");
		for (BlogPost o:obj.getBlogPosts()) {
			marshal(writer, "blogPosts", o, false);
		}
		writer.write("<services>" + escape(obj.getServices()) + "</services>");
		writer.write("<points>" + escape(new com.jrapid.controller.servers.castor.IntegerHandler().convertUponGet(obj.getPoints())) + "</points>");
		writer.write("<email>" + escape(obj.getEmail()) + "</email>");
		writer.write("<gender>" + escape(obj.getGender()) + "</gender>");
		writer.write("<birthday>" + escape(obj.getBirthday()) + "</birthday>");
		writer.write("<phoneNumbers>" + escape(obj.getPhoneNumbers()) + "</phoneNumbers>");
		writer.write("<media>" + escape(obj.getMedia()) + "</media>");
		writer.write("<clients>" + escape(obj.getClients()) + "</clients>");
		writer.write("<appointments>" + escape(obj.getAppointments()) + "</appointments>");
		writer.write("<alerts>" + escape(obj.getAlerts()) + "</alerts>");
		writer.write("</" + nodeName + ">");
	}	

		
	public void marshal(Writer writer, String nodeName, Role obj, Boolean showSecondary) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<name>" + escape(obj.getName()) + "</name>");
		
		writer.write("</" + nodeName + ">");
	}
	
	public void marshalFull(Writer writer, String nodeName, Role obj, Boolean foo) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<name>" + escape(obj.getName()) + "</name>");	
		for (Object o:obj.getPrivileges()) {
				
			writer.write("<privileges>" + escape(o) + "</privileges>");
					
		}
		writer.write("</" + nodeName + ">");
	}	

		
	public void marshal(Writer writer, String nodeName, Login obj, Boolean showSecondary) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " />");
			return;
		}
		writer.write("<" + nodeName + " style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<username>" + escape(obj.getUsername()) + "</username>");
		
		writer.write("</" + nodeName + ">");
	}
	
	public void marshalFull(Writer writer, String nodeName, Login obj, Boolean foo) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " />");
			return;
		}
		writer.write("<" + nodeName + " style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<username>" + escape(obj.getUsername()) + "</username>");
		writer.write("<password>" + escape(obj.getPassword()) + "</password>");
		writer.write("<schema>" + escape(obj.getSchema()) + "</schema>");
		writer.write("</" + nodeName + ">");
	}	

		
	public void marshal(Writer writer, String nodeName, ChangePassword obj, Boolean showSecondary) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " />");
			return;
		}
		writer.write("<" + nodeName + " style='" + escape(obj.getStyle()) + "' >");
		
		
		writer.write("</" + nodeName + ">");
	}
	
	public void marshalFull(Writer writer, String nodeName, ChangePassword obj, Boolean foo) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " />");
			return;
		}
		writer.write("<" + nodeName + " style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<newPassword>" + escape(obj.getNewPassword()) + "</newPassword>");
		writer.write("<confirmPassword>" + escape(obj.getConfirmPassword()) + "</confirmPassword>");
		writer.write("</" + nodeName + ">");
	}	

		
	public void marshal(Writer writer, String nodeName, Location obj, Boolean showSecondary) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		
		writer.write("</" + nodeName + ">");
	}
	
	public void marshalFull(Writer writer, String nodeName, Location obj, Boolean foo) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<country>" + escape(obj.getCountry()) + "</country>");
		writer.write("<state>" + escape(obj.getState()) + "</state>");
		writer.write("<locality>" + escape(obj.getLocality()) + "</locality>");
		writer.write("<street>" + escape(obj.getStreet()) + "</street>");
		writer.write("<number>" + escape(new com.jrapid.controller.servers.castor.IntegerHandler().convertUponGet(obj.getNumber())) + "</number>");
		writer.write("<appartment>" + escape(obj.getAppartment()) + "</appartment>");
		writer.write("</" + nodeName + ">");
	}	

		
	public void marshal(Writer writer, String nodeName, Review obj, Boolean showSecondary) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		
		writer.write("</" + nodeName + ">");
	}
	
	public void marshalFull(Writer writer, String nodeName, Review obj, Boolean foo) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		marshal(writer, "client", obj.getClient(), false);
		writer.write("<text>" + escape(obj.getText()) + "</text>");
		writer.write("<rating>" + escape(new com.jrapid.controller.servers.castor.IntegerHandler().convertUponGet(obj.getRating())) + "</rating>");
		marshal(writer, "user", obj.getUser(), false);
		writer.write("</" + nodeName + ">");
	}	

		
	public void marshal(Writer writer, String nodeName, Experience obj, Boolean showSecondary) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		
		writer.write("</" + nodeName + ">");
	}
	
	public void marshalFull(Writer writer, String nodeName, Experience obj, Boolean foo) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<area>" + escape(obj.getArea()) + "</area>");
		writer.write("<text>" + escape(obj.getText()) + "</text>");
		marshal(writer, "user", obj.getUser(), false);
		writer.write("</" + nodeName + ">");
	}	

		
	public void marshal(Writer writer, String nodeName, BlogPost obj, Boolean showSecondary) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		
		writer.write("</" + nodeName + ">");
	}
	
	public void marshalFull(Writer writer, String nodeName, BlogPost obj, Boolean foo) throws Exception {
		if (obj == null) {
			writer.write("<" + nodeName + " id=''  />");
			return;
		}
		writer.write("<" + nodeName + " id='" + escapeAttr(obj.getId()) + "'  style='" + escape(obj.getStyle()) + "' >");
		
		writer.write("<title>" + escape(obj.getTitle()) + "</title>");
		writer.write("<description>" + escape(obj.getDescription()) + "</description>");
		writer.write("<body>" + escape(obj.getBody()) + "</body>");
		marshal(writer, "user", obj.getUser(), false);
		writer.write("</" + nodeName + ">");
	}	

	
}

	